#include "StdAfx.h"
#include "Worker.h"
#include <process.h>

Worker::Worker(void)
{
	_State = Stopped;
	_hThread = 0;
}

Worker::~Worker(void)
{
}

void Worker::_run(void * data)
{
	Worker * w = (Worker*)data;
	w->_State = Started;
	w->OnRun();
	w->_State = Stopped;
	_endthread();
	w->_hThread = 0;
}

void Worker::Start(void)
{
	_hThread = _beginthread(_run, 0, this);
}

void Worker::Stop(void)
{
	_State = Stopping;
}

void Worker::Join(void)
{
	if (_hThread != 0)
		WaitForSingleObject((HANDLE)_hThread, INFINITE);
}



